#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n = 0;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; ++i)
        cin >> arr[i];

    vector<vector<int>> dp(n, vector<int>(n));

    long long count = 0;
    for (int i = n - 2; i >= 0; --i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            dp[i][j] = dp[i + 1][j - 1];
            if (arr[i] != arr[j])
                ++dp[i][j];
            count += dp[i][j];
        }
    }
    cout << count << endl;
    return 0;
}